package cn.edu.anan.controller;

import cn.edu.anan.config.ConsumerNacosConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * <p>
 * 消费者controller
 * </p>
 *
 * @author yanghouhua@edu.com.cn
 * @since 2021/8/11
 */
@RestController
@RequestMapping("consumer")
@Slf4j
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @Value("${spring.cloud.nacos.discovery.cluster-name}")
    private String clusterName;

    @RequestMapping("test")
    public String test(){
        log.info("准备调用服务提供者api：follow-me-springloud-nacos-provider");
        String result = restTemplate.getForObject("http://follow-me-springloud-nacos-provider/provider/test", String.class);

        result = "消费者，部署在："+ clusterName +" 机房." + result;
        return result;
    }

    @Autowired
    private ConsumerNacosConfig consumerNacosConfig;

    @RequestMapping("config")
    public String testConfig(){
        log.info("ConsumerController---testConfig.当前配置信息：{}", consumerNacosConfig);

        return consumerNacosConfig.toString();
    }

}
